<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>protojs User information example</title>

<script type="text/javascript" src="jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="protobuf.js"></script>
<script type="text/javascript" src="pbj.js"></script>
<script type="text/javascript" src="User.proto.js"></script>

</head>
<body>

<pre id="output" style="font-size: 14px;"></pre>

<script type="text/javascript">
//<![CDATA[
jQuery(document).ready(function() {
	/* 数组流 */ 
    var array = [];
    var arraystream = PROTO.ByteArrayStream(array);

    /* base64字符串流 */
    var stream = new PROTO.Base64Stream();

    /* 消息 */
    var user = new passport.User();
    user.username = "hezhiqiang";
    user.password = "qwertyuioptre23456789of";
    user.email = "qwertyuioptre23456789of@gmail.com";
    user.tel = "13888888888";

    var output = $("#output");

    /* 序列化消息 */
    user.SerializeToStream(stream);

    var serialized = stream.getString();

    /* Ajax 选项 */
    var options  = {};
    options.type = 'POST';
    options.data = 'message='+serialized;
    options.cache = false;
    options.url = 'protoclasses/_User.php';
    options.success = function(responseText, textStatus){
        /* 实例化消息*/
        var s = new passport.User();
        /* 解码反序列化消息*/
        s.ParseFromStream(new PROTO.Base64Stream(responseText));
        for( p in s){
        	$("#output").append(p + "<br/>");
        }
        
    };

    /* Ajax 请求 */
    $.ajax(options);
});
//]]>
</script>


</body>
</html>